<template>
  <el-card>
    <template #header>
      <el-row :gutter="10" style="float: right">
        <el-button @click="emit('addDataRule')" type="primary">新 增</el-button>
        <el-button @click="deleteRow" :icon="Delete" type="danger" plain
          >删 除</el-button
        >
      </el-row>
    </template>
  </el-card>
  <ts-card header="数据规则列表" style="margin-top: 10px">
    <el-table
      ref="table"
      :data="dataList"
      height="600"
      @select="selectRow"
      @select-all="selectAll"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="id" label="记录id"></el-table-column>
      <el-table-column prop="name" label="对象属性名"></el-table-column>
      <el-table-column prop="title" label="字段标题"></el-table-column>
      <el-table-column prop="extendId" label="引用别的数据规则ID"></el-table-column>
      <el-table-column prop="matchMethods" label="执行的方法集合"></el-table-column>
      <el-table-column prop="generateNums" label="生成编码的个数"></el-table-column>
      <el-table-column prop="dbService" label="数据源类型"></el-table-column>
      <el-table-column prop="interceptorOrder" label="拦截顺序"></el-table-column>
      <el-table-column label="可是否自动处理">
        <template #default="scope">
          <el-switch v-model="scope.row.autoHandle" disabled></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="edit(scope)"
            >修 改</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </ts-card>
</template>
    <script setup>
import { ref, defineModel, onMounted, computed, nextTick, inject } from "vue";
import { Plus, Delete, DCaret, Edit } from "@element-plus/icons-vue";
import { ElMessageBox, ElMessage } from "element-plus";
import API from "@/api/model/meta.js";
const emit = defineEmits(["toDetail", "addDataRule", "delete", "update"]);
const fileName = inject("fileName");
const table = ref(null);
const dataList = defineModel();
const deleteList = ref([]);
onMounted(() => {});
const edit = (scope) => {
  emit("toDetail", scope.row);
};
const selectRow = (rows, row) => {
  deleteList.value = rows;
};
const selectAll = (rows) => {
  deleteList.value = rows;
};
const deleteRow = async () => {
  if (deleteList.value.length > 0) {
    let param = {
      fileName: fileName.value,
      dataList: deleteList.value.map((ele) => {
        return ele.fieldId;
      }),
    };
    ElMessageBox.confirm("确定删除吗？", "提示", {
      type: "warning",
      confirmButtonText: "确定",
      confirmButtonClass: "el-button--danger",
    })
      .then(async () => {
        let res = await API.businessrule.deteleData.post(param);
        if (res.code == 200) {
          emit("delete");
          emit("update");
        }
      })
      .catch(() => {});
  } else {
    ElMessage({
      message: "请选择表格记录",
      type: "warning",
    });
  }
};
</script>
    <style lang="less" scoped></style>